﻿using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using YawetagDemo.Framework.Data;

namespace YawetagDemo.Framework.Server.Data
{
    [DataContract(IsReference = true)]
    public class WCFArtist : IArtist
    {
        private WCFArtist(IArtist artist, IDictionary<object, object> references)
        {
            references.Add(artist, this);

            ArtistID = artist.ArtistID;

            Person = WCFPerson.Get(artist.Person, references);
            Bands = artist.Bands.Select(i => WCFBand.Get(i, references)).ToList();
        }

        public static WCFArtist Get(IArtist artist, IDictionary<object, object> references)
        {
            return (WCFArtist)(references.ContainsKey(artist) ? references[artist] : new WCFArtist(artist, references));
        }

        [DataMember] public int ArtistID { get; private set; }

        [DataMember] public WCFPerson Person { get; private set; }
        IPerson IArtist.Person { get { return Person; } }

        [DataMember] public IList<WCFBand> Bands { get; private set; }
        IList<IBand> IArtist.Bands { get { return Bands.OfType<IBand>().ToList(); } }
    }
}
